import 'package:flutter/cupertino.dart';
import 'package:good_good_study/common/index.dart';
import 'package:good_good_study/common/widget/reminder/top_reminder.dart';
import 'package:good_good_study/entity/home_list_entity.dart' as Article;
import 'package:good_good_study/repository/http.dart';

class HomeProvider extends ChangeNotifier {
  List<Article.Datas> articleList = [];

  bool isNoMore = false;

  int nextPageIndex = 0;

  getListPage(NetCancel netCancel, {page}) {
    var realPage = page ?? nextPageIndex;
    Http.getHomeList(page: realPage).listen((entity) {
      if (realPage == 0) {
        articleList.clear();
      }
      articleList.addAll(entity.data.datas);
      isNoMore = entity.data.over;
      nextPageIndex = entity.data.curPage;
      notifyListeners();
    }, onError: (err) {
      if (err is NetError) {
        TopReminder.error(netCancel.context, err.msg);
      }
    });
  }

  updateItem(int pos, Article.Datas item) {
    articleList[pos] = item;
    notifyListeners();
  }

  doChange() {
    notifyListeners();
  }
}
